package com.changhai.diabetes.util;

import java.util.HashMap;
import java.util.Map;
import javax.sql.DataSource;
import org.springframework.orm.ibatis.SqlMapClientFactoryBean;
import com.ibatis.sqlmap.client.SqlMapClient;


/**
 * 生成多个SqlMapClient
 * @author Andy
 *
 */
public class MySqlMapClientFactoryBean extends SqlMapClientFactoryBean {

	private static Map<String, DataSource> dataSourceMap = new HashMap<String, DataSource>();// 用于存放数据源dataSource
	private static Map<String, SqlMapClient> sqlMapClientMap = new HashMap<String, SqlMapClient>();// 用于SqlMapClient
	private static String defaultDataSourceName = null;

	public void afterPropertiesSet() throws Exception {
		for (Object obj : dataSourceMap.keySet()) {
			setDataSource(dataSourceMap.get(obj));
			super.afterPropertiesSet();
			sqlMapClientMap.put(obj.toString(), (SqlMapClient) getObject());
		}
	}

	public void setDataSourceMap(Map<String, DataSource> dataSourceMap) {
		this.dataSourceMap = dataSourceMap;
	}

	public static Map<String, DataSource> getDataSourceMap() {
		return dataSourceMap;
	}

	public static Map<String, SqlMapClient> getSqlMapClientMap() {
		return sqlMapClientMap;
	}

	public void setDefaultDataSourceName(String defaultDataSourceName) {
		this.defaultDataSourceName = defaultDataSourceName;
	}

	public static String getDefaultDataSourceName() {
		return defaultDataSourceName;
	}
}
